<?php


namespace seecms\lib\builder\control;

class InputControl extends Control
{
    protected $type = 'text';

    public function render(): string
    {
        $prefix = $this->prefix ? '<div class="layui-input-split layui-input-prefix" style="cursor: pointer;"><i class="layui-icon ' . $this->prefix . '"></i></div>' : '';
        $suffix = $this->suffix ? '<div class="layui-input-split layui-input-suffix" style="cursor: pointer;"><i class="layui-icon ' . $this->suffix . '"></i></div>' : '';

        $required = $this->required ? '<span class="layui-font-red">*</span>' : '';
        $readonly = $this->readonly ? 'readonly' : '';
        $disabled = $this->disabled ? 'disabled' : '';
        $description = $this->getDescription();

        $input_group = '';
        if ($prefix || $suffix) {
            $input_group = 'layui-input-group';
        }

        $display = 'block';
        $container = '<div class="layui-form-item">';
        if ($this->inline == 'inline') {
            $display = 'inline';
            $container = '<div class="layui-inline">';
        }

        return <<<EOF
$container
   <label class="layui-form-label">
        {$this->label}
        {$required}
    </label>
    <div class="layui-input-$display {$input_group}">
        {$prefix}
        <input class="layui-input"
               type="{$this->type}"
               name="{$this->name}"
               placeholder="{$this->placeholder}"
               value="{$this->value}"
               $readonly
               $disabled
        >
        {$suffix}
        $description
    </div>
</div>
EOF;
    }
}